//////////Change the directory before running the code
////////// Panel A
cd "D:\data&code"
// Left panel
quietly {

	// Load dataset
	use pseudo_dataset/edgar_b, clear

	// Interaction
	gen INTER = event_window*pass_family
	label variable INTER			"Passive family x Around contest"

	// Left panel
	areg view_d pass_family agg_ownershipw if event_window==1, ab(meetingid ) vce(cluster gvkey)
	outreg2 using table_8a, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes replace

	areg view_d pass_family agg_ownershipw if event_window==0 & year2event<=0, ab(meetingid ) vce(cluster gvkey)
	outreg2 using table_8a, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

	areg view_d pass_family agg_ownershipw if event_window==0 & year2event>=0, ab(meetingid ) vce(cluster gvkey)
	outreg2 using table_8a, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

	xi: areg view_d INTER agg_ownershipw i.fund_family_id, ab(meetingid) vce(cluster gvkey)
	outreg2 using table_8a, keep(pass_family agg_ownershipw INTER) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append
	
}


sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==1
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==0 & year2event<=0
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==0 & year2event>=0
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window~=.


// Right panel
quietly {
keep if big3 == 0
	
areg view_d pass_family agg_ownershipw if event_window==1, ab(meetingid ) vce(cluster gvkey)
outreg2 using table_8a, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

areg view_d pass_family agg_ownershipw if event_window==0 & year2event<=0, ab(meetingid ) vce(cluster gvkey)
outreg2 using table_8a, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

areg view_d pass_family agg_ownershipw if event_window==0 & year2event>=0, ab(meetingid ) vce(cluster gvkey)
outreg2 using table_8a, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

xi: areg view_d INTER agg_ownershipw i.fund_family_id, ab(meetingid) vce(cluster gvkey)
outreg2 using table_8a, keep(pass_family agg_ownershipw INTER) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append
}

sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==1
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==0 & year2event<=0
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==0 & year2event>=0
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window~=.

// View regression table
use table_8a_dta, clear
rm table_8a.txt
browse

////////// Panel B

// Left panel
quietly {

	// Load dataset
	use pseudo_dataset/edgar_a, clear

	keep if contest==2

	// Interaction
	gen INTER = event_window*pass_family
	label variable INTER			"Passive family x Around contest"

	// Left panel
	areg view_d pass_family agg_ownershipw if event_window==1, ab(meetingid ) vce(cluster gvkey)
	outreg2 using table_8b, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes replace

	areg view_d pass_family agg_ownershipw if event_window==0 & year2event<=0, ab(meetingid ) vce(cluster gvkey)
	outreg2 using table_8b, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

	areg view_d pass_family agg_ownershipw if event_window==0 & year2event>=0, ab(meetingid ) vce(cluster gvkey)
	outreg2 using table_8b, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

	xi: areg view_d INTER agg_ownershipw i.fund_family_id, ab(meetingid) vce(cluster gvkey)
	outreg2 using table_8b, keep(pass_family agg_ownershipw INTER) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append
	
}

sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==1
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==0 & year2event<=0
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==0 & year2event>=0
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window~=.

// Right panel
quietly {
keep if big3 == 0
	
areg view_d pass_family agg_ownershipw if event_window==1, ab(meetingid ) vce(cluster gvkey)
outreg2 using table_8b, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

areg view_d pass_family agg_ownershipw if event_window==0 & year2event<=0, ab(meetingid ) vce(cluster gvkey)
outreg2 using table_8b, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

areg view_d pass_family agg_ownershipw if event_window==0 & year2event>=0, ab(meetingid ) vce(cluster gvkey)
outreg2 using table_8b, keep(pass_family agg_ownershipw) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append

xi: areg view_d INTER agg_ownershipw i.fund_family_id, ab(meetingid) vce(cluster gvkey)
outreg2 using table_8b, keep(pass_family agg_ownershipw INTER) label dta tstat adjr2 bracket bdec(3) tdec(2) nocons nonotes append
}
	
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==1
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==0 & year2event<=0
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window==0 & year2event>=0
sum view_d if pass_family~=. & agg_ownershipw~=. & event_window~=.
	
// View regression table
use table_8b_dta, clear
rm table_8b.txt
browse
